#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main()
{
	int a, b;
	char str[40];
	while (scanf("%d%s%d", &a, str, &b) != EOF)
	{
		int tmp = 0, c = 1;
		int len = strlen(str)-1;
		for (int i = len; i >= 0; i--)
		{
			int x;
			if (str[i] >= '0' && str[i] <= '9')
			{
				x = str[i] - '0';
			}
			else if (str[i] >= 'a' && str[i] <= 'z')
			{
				x = str[i] - 'a' + 10;
			}
			else {
				x= str[i] - 'A' + 10;
			}
			tmp += x * c;
			c *= a;
		}
		char ans[40];
		int i = 0;
		do {
			int x = tmp % b;
			ans[i++] = (x < 10) ? x + '0' : x - 10 + 'A';
			tmp /= b;
		} while (tmp);
		for (tmp = i - 1; tmp >= 0; tmp--)
		{
			printf("%c", ans[tmp]);
		}
		puts("\n");
	}
	return 0;
}